﻿using Pub.DBUtility;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Pub.DBService
{
    /// <summary>
    /// 数据库访问服务类
    /// </summary>
    public class clsDBService
    {
        /// <summary>
        /// 数据库连接字符串 可以设置默认数据库
        /// </summary>
        private string m_strCon = "";
        private IDataBaseService IDBService = null;
        public clsDBService(string strCon)
        {
            m_strCon = strCon;
            IDBService = GetDBService();
        }

        IDataBaseService GetDBService()
        {
            //读取文件选择构造对象
           // return new clsSQLServerHelper(m_strCon);
            return new clsSQLLiteHelper(m_strCon);
        }

        public void m_mthCreateDB(string strDbName)
        {
            IDBService.m_mthCreateDB(strDbName);
        }

        /// <summary>
        /// 获取数据
        /// </summary>
        /// <param name="strSQL"></param>
        /// <param name="dtResult"></param>
        /// <param name="Params"></param>
        /// <returns></returns>
        long GetTableWithParams(String strSQL, ref DataTable dtResult, params IDataParameter[] Params)
        {
            return IDBService.GetTableWithParams(strSQL,ref dtResult, Params);
        }
        /// <summary>
        /// 执行有参数
        /// </summary>
        /// <param name="strSQL"></param>
        /// <param name="AffectedCount"></param>
        /// <param name="Params"></param>
        /// <returns></returns>
        long ExecParamSQL(String strSQL, ref long AffectedCount, params IDataParameter[] Params)
        {
            return IDBService.ExecParamSQL(strSQL,ref AffectedCount, Params);
        }
        /// <summary>
        /// 有参数存储过程
        /// </summary>
        /// <param name="strSQL"></param>
        /// <param name="strConnect"></param>
        /// <param name="Params"></param>
        /// <returns></returns>
        long ExecParamProc(String strSQL, params IDataParameter[] Params)
        {
            return IDBService.ExecParamProc(strSQL, Params);
        }

        long GetTableFromProc(string strProcName, ref DataTable dtResult)
        {
           return IDBService.GetTableFromProc(strProcName, ref dtResult);
        }


    }
}
